home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / snip0493.zip / SCRNSAVE.C < prev    next >
C/C++ Source or Header  |  1993-04-05  |  2KB  |  80 lines

  1. /*
  2. **  SCRNSAVE.C - Save and restore text screen portably
  3. **
  4. **  public domain demo by Bob Stout
  5. */
  6.  
  7. #include <stdlib.h>
  8.  
  9. /*
  10. **  Stuff from SNIPPETS courtesy of Jim Nutt
  11. **
  12. **  Notes: VIOopen() is called redundantly to assure that the video
  13. **         information is always initialized. These multiple calls are benign.
  14. **
  15. **         Because of using VIO.OBJ, this *must* be compiled in large model!
  16. */
  17.  
  18. #include "vio.h"
  19.  
  20. /*
  21. **  Save the current text screen
  22. **
  23. **  Arguments: None
  24. **
  25. **  Returns: Pointer to saved screen buffer, NULL if insufficient heap
  26. */
  27.  
  28. unsigned short *savescreen(void)
  29. {
  30.       unsigned short *vbuf;
  31.  
  32.       VIOopen();
  33.       if (NULL == (vbuf = malloc(VIOcolumns() * VIOrows() * 2)))
  34.             return NULL;
  35.       VIOgetra(0, 0, VIOcolumns() - 1, VIOrows() - 1, (int _far *)vbuf);
  36.       return vbuf;
  37. }
  38.  
  39. /*
  40. **  Restore a screen previously saved by savescreen()
  41. **
  42. **  Arguments: Buffer containing the screen to restore
  43. **
  44. **  Returns: Nothing
  45. **
  46. **  WARNING: No error checking done to verify same screen size and mode!
  47. */
  48.  
  49. void restorescreen(unsigned short *vbuf)
  50. {
  51.       VIOopen();
  52.       VIOputr(0, 0, VIOcolumns(), VIOrows(), (int _far *)vbuf);
  53.       free(vbuf);
  54. }
  55.  
  56. #ifdef TEST
  57.  
  58. #include <stdio.h>
  59. #include <conio.h>
  60.  
  61. int main(void)
  62. {
  63.       unsigned short *vbuf;
  64.  
  65.       VIOopen();
  66.       if (NULL == (vbuf = savescreen()))
  67.       {
  68.             puts("Unable to save screen");
  69.             return EXIT_FAILURE;
  70.       }
  71.       VIOclear(0, 0, VIOcolumns(), VIOrows());
  72.       puts("Hit any key to exit");
  73.       getch();
  74.       restorescreen(vbuf);
  75.       VIOclose();
  76.       return EXIT_SUCCESS;
  77. }
  78.  
  79. #endif /* TEST */
  80.